package org.csu.demopetstore.Service;

import org.apache.ibatis.annotations.Param;
import org.csu.demopetstore.Persistence.CartMapper;
import org.csu.demopetstore.entity.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class CartService {

    @Autowired
    private CartMapper cartMapper;

    public List<Cart> getCartList(String username){
        return cartMapper.getCartList(username);
    }

    public void insertCart(Cart cart){
        cartMapper.insertCart(cart);
    }
    public Cart getCartByUsernameAndItemid(String username, String itemid){
        return cartMapper.getCartByUsernameAndItemid(username,itemid);
    }
    public void updateCart(String username, String itemid, Cart cart){
        cartMapper.updateCart(username,itemid,cart.getQuantity(),cart.getTotal());
    }
    public boolean getInstock(String itemid){
        return cartMapper.getInstock(itemid);
    }

    public void deleteCartByUsernameAndItemid(String username,String itemid){
        cartMapper.deleteCartByUsernameAndItemid(username,itemid);
    }

    public BigDecimal calculation(String username){
        return cartMapper.calculation(username);
    }

    public void deleteAllCart(@Param("username")String username){
        cartMapper.deleteAllCart(username);
    }

}
